package com.onlineshop.highgee.daoimpl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import com.onlineshop.highgee.dao.MyOrderStatusDao;
import com.onlineshop.highgee.entity.MyOrder;
import com.onlineshop.highgee.entity.OrderStatus;
import com.onlineshop.highgee.exception.MyOrderStatusDaoException;

/**
 * 
 * @author 932080531
 * @date 2019骞�12鏈�23鏃� 涓嬪崍7:47:50
 * @version 1.0
 */
public class MyOrderStatusDaoImpl implements MyOrderStatusDao {

	// @Override
	// public void addCateStatus(OrderStatus orderstatus) throws
	// MyOrderStatusDaoException {
	// // TODO Auto-generated method stub
	// Connection con;
	// PreparedStatement pre;
	// String sql="insert into highgee_orderinformation (state) values(?)";
	// try {
	// Class.forName("com.mysql.jdbc.Driver");
	// String
	// uri="jdbc:mysql://127.0.0.1:3306/highgee?user=root&password=root&characterEncoding=utf-8";
	// con=DriverManager.getConnection(uri);
	// pre=con.prepareStatement(sql);
	// pre.setInt(1, orderstatus.getStatusName());
	// pre.executeUpdate();
	// con.close();
	// }catch(Exception e){
	// e.printStackTrace();
	// }
	// }

	/**
	 * 淇敼璁㈠崟鐘舵��
	 * 
	 * @return
	 * 
	 */
	@Override
	public void updateStatus(OrderStatus orderstatus, MyOrder myOrder) throws MyOrderStatusDaoException {
		// TODO Auto-generated method stub
		Connection con;
		PreparedStatement pre;
		String sql = "update my_order set order_state=? where order_number=?";
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String uri = "jdbc:mysql://127.0.0.1:3306/highgee?user=root&password=&characterEncoding=utf-8";
			con = DriverManager.getConnection(uri);
			pre = con.prepareStatement(sql);
			pre.setInt(1, orderstatus.getStatusName());
			pre.setLong(2, myOrder.getOrder_number());
			pre.executeUpdate();
			con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 鍒犻櫎璁㈠崟鐘舵��(鍩烘湰涓婄敤涓嶄笂)
	 * 
	 * @return
	 * 
	 */
	@Override
	public void deleteStatus(OrderStatus orderstatus, MyOrder myOrder) throws MyOrderStatusDaoException {
		// TODO Auto-generated method stub
		Connection con;
		PreparedStatement pre;
		String sql = "delete from my_order where order_number=?";
		try {
			Class.forName("com.mysql.jdbc.Driver");
			String uri = "jdbc:mysql://127.0.0.1:3306/highgee?user=root&password=&characterEncoding=utf-8";
			con = DriverManager.getConnection(uri);
			pre = con.prepareStatement(sql);
			pre.setLong(1, myOrder.getOrder_number());
			pre.executeUpdate();
			con.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
